package com.manor.main.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.manor.main.R;

import com.manor.common.CommonAppConfig;
import com.manor.common.activity.AbsActivity;
import com.manor.common.http.HttpCallback;
import com.manor.common.utils.RouteUtil;
import com.manor.common.utils.ToastUtil;
import com.manor.common.utils.WordUtil;
import com.manor.main.http.MainHttpUtil;

/**
 * 添加账户
 */
@Route(path = RouteUtil.PC_ADDACCOUNT)
public class AddAccountActivity extends AbsActivity {
    ImageView rl_confirm;
    EditText ed_id, ed_name;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_addaccount;
    }

    @Override
    protected void main() {
        setTitle(WordUtil.getString(R.string.WITHDRAWAL_ADD_ACCOUNT));
        rl_confirm = findViewById(R.id.rl_confirm);
        ed_id = findViewById(R.id.ed_id);
        ed_name = findViewById(R.id.ed_name);
        rl_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rl_confirm.setClickable(false);
                if (!ed_id.getText().equals("") && !ed_name.getText().equals("")) {
                    MainHttpUtil.SetUserAccount(CommonAppConfig.getInstance().getUid(), CommonAppConfig.getInstance().getToken(),
                            ed_id.getText().toString(), ed_name.getText().toString(), new HttpCallback() {
                                @Override
                                public void onSuccess(int code, String msg, String info) {
                                    if (code == 0) {
                                        ToastUtil.show(msg);
                                        finish();
                                    } else {
                                        ToastUtil.show(msg);
                                        rl_confirm.setClickable(true);
                                    }

                                }

                                @Override
                                public void onError() {
                                    super.onError();
                                    rl_confirm.setClickable(true);
                                }

                            });
                } else {
                    ToastUtil.show("请输入账号/姓名");
                }
            }
        });
    }
}
